#include "main/utils.h"
using namespace std;

int longestSubStr(const string &str) {
  int max_num = 0;
  int cur_num = 0;
  map<char, int> help_map;
  for (int i = 0; i < str.length(); ++i) {
    if (help_map.find(str[i]) == help_map.end() ||
        i - help_map[str[i]] > cur_num) {
      ++cur_num;
    } else {
      cur_num = i - help_map[str[i]];
    }
    help_map[str[i]] = i;
    if (cur_num > max_num)
      max_num = cur_num;
  }
  return max_num;
}

int main() {
  string str = "abcdeeeeeeeeeea";
  int ret = longestSubStr(str);
  cout << "The longest sub string without duplicate character: " << ret << " expected: 5" << endl;

  ret = longestSubStr("abcacfrar");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 4" << endl;

  ret = longestSubStr("acfrarabc");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 4" << endl;

  ret = longestSubStr("arabcacfr");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 4" << endl;

  ret = longestSubStr("aaaa");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 1" << endl;

  ret = longestSubStr("abcdefg");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 7" << endl;

  ret = longestSubStr("aaabbbccc");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 2" << endl;

  ret = longestSubStr("abcdcba");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 4" << endl;

  ret = longestSubStr("abcdaef");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 6" << endl;

  ret = longestSubStr("a");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 1" << endl;

  ret = longestSubStr("");
  cout << "The longest sub string without duplicate character: " << ret << " expected: 0" << endl;

  return 0;
}
